<?php if (! class_exists ('Views')) die ('access denied') ?>
<h1>Admin pane</h1>


<h2>Invoices</h2>
<?php if ($Invoices = $GLOBALS ['PG']->FetchTable ('select * from "Invoices";')) { ?>
<dl>
	<?php foreach ($Invoices as $Invoice) { ?>
	<dt><a href="?Views[next]=invoice&Views[id]=<?php HTML::E ($Invoice ['Number']) ?>& "><?php HTML::E ($Invoice ['Number']) ?></a></dt>
	<dd>
		<?php HTML::E (MakeDate ($Invoice ['Start'])) ?>
		&ndash;
		<?php HTML::E (MakeDate ($Invoice ['End'])) ?>
	</dd>
	<?php } ?>
</dl>
<?php } else { ?>
	<div>No invoices have been uploaded yet</div>
<?php } ?>
<?php echo (modInvoices::Form ()) ?>


<h2>Users</h2>
<?php if ($Unmapped = $GLOBALS ['PG']->FetchTable ('select distinct "Owner" from "Calls" union select distinct "Owner" from "GPRS" union select distinct "Owner" from "SMS" union select distinct "Owner" from "MMS" except select "Number" from "Users" order by "Owner";')) { ?>
<h3>Stray numbers</h3>
<ul>
	<?php foreach ($Unmapped as $Number) { ?>
		<li><?php HTML::E ($Number ['Owner']) ?></li>
	<?php } ?>
</ul>
<?php } ?>

<?php if ($Users = $GLOBALS ['PG']->FetchTable ('select * from "Users" order by "Username";')) { ?>
	<h3>Assigned numbers</h3>
	<?php echo (modUsers::Form ($Users)) ?>
<?php } ?>

<h3>Add a new user</h3>
<?php echo (modUsers::Form ()) ?>
